<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>购买详情</title>
    <link href="css/bootstrap.css" rel="stylesheet">
    <script src="js/jquery-3.6.4.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/popper.js/2.9.3/umd/popper.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</head>
<body>
<div id="top"></div>
<div class="container" style="background-color: white;">
    <div class="row" style="margin-left: 40px;margin-top:0%">
        <h3>购买详情&nbsp;&nbsp;</h3>
    </div>
    <div class="row" style="margin-top: 40px;">
        <div class="col-md-12">
            <table id="tb_list" class="table table-striped table-hover table-bordered table-condensed">
                <tr>
                    <th>序号</th>
                    <th>订单编号</th>
                    <th>订单时间</th>
                    <th>购买者</th>
                    <th>商品名称</th>
                    <th>购买数量</th>
                    <th>购买小计</th>
                    <th>订单状态</th>
                </tr>
                <tbody id="sell-list" style="table-layout: fixed;border-collapse: collapse"></tbody>
            </table>
        </div>
    </div>

</div>

<script type="text/javascript">
    $(function (){
        $("#top").load("top2.html")
        $.ajax({
            url: "/PDD/order?method=showSellDetail",
            dataType: "json",
            success: function (data) {
                let sellList=data.data
                let html=""
                for (let i = 1; i <= sellList.length; i++) {
                    let sell = sellList[i-1]
                    html += `
<tr>
  <th>${i}</th>
  <th>${sell.oId}</th>
  <th>${sell.oTime}</th>
  <th>${sell.buyer}</th>
  <th>${sell.pName}</th>
  <th>${sell.iNum}</th>
  <th>${sell.iCount.toFixed(2)}</th>
  <th>
     <span id="state${i}" style="color: red"></span>
  </th>
</tr>
`;
                }
                $("#sell-list").html(html)
                for (let i = 1; i <= sellList.length; i++) {
                    let sell = sellList[i-1]
                    //根据订单状态更换提示信息
                    let state=parseInt(sell.oState)
                    if(state===0){
                        $("#state"+i).html("未支付")
                    }else if(state===1){
                        $("#state"+i).html("已支付未确认")
                    }else if(state===2){
                        $("#state"+i).html("订单已完成")
                    }
                }
            },
            error: function (jqXHR) {
                alert("失败" + jqXHR.responseText); // 输出响应内容
            }
        })
    })
</script>
</body>
</html>